﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebControl_PasswordSet : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Model.SessionUser model = BaseLogin.getSessionNode(HttpContext.Current);
            this.lblName.Text = model.userName;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strOldPwd = this.txtOldPwd.Text;
        string strNewPwd = this.txtNewPwd.Text;
        string strNewPwd1 = this.txtNewPwd1.Text;

         if (strOldPwd == "")
        {
            this.lblMsg.Text = "原密码不能为空！";
            return;
        }
        if (strNewPwd == "" || strNewPwd1 == "")
        {
            this.lblMsg.Text = "新密码不能为空！";
            return;
        }
        if (strNewPwd1 != strNewPwd)
        {
            this.lblMsg.Text = "两次输入的密码不一致";
            return;
        }
        BLL.UserBLL bll = new BLL.UserBLL();
        Model.SessionUser model = BaseLogin.getSessionNode(HttpContext.Current);
        if (bll.ChangePassword(model.uid, strOldPwd, strNewPwd))
        {
            BaseLogin.ClearSession(HttpContext.Current); 
            Response.Redirect("../login.aspx");
        }
        else
        {
            this.lblMsg.Text = "原密码输入错误！";
            this.txtOldPwd.Text = "";
        }
    }
}
